#include<bits/stdc++.h>
using namespace std;

class Solution {
public:
    bool judge(string& a, string& b, unordered_map<char, int>mp){
        int i = 0;
        while(i < a.length() && i < b.length()){
            if(a[i] != b[i])return mp[a[i]] < mp[b[i]];
            else i++;
        }
        return a.length() < b.length();
    }
    bool isAlienSorted(vector<string>& words, string order) {
        unordered_map<char, int>mp;
        for(int i = 0; i < order.length(); i++)mp[order[i]] = i;
        for(int i = 0; i + 1 < words.size(); i++){
            if(!judge(words[i], words[i + 1], mp))return false;
        }
        return true;
    }
};

/**
 * @brief 2022.5.17
 * 模拟
 * 
 */